﻿using System;
using PTiRouZ.Net.SilverLight.Api;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

namespace PTiRouZ.Net.SilverLight.Api.HelloTipi
{
    /// <summary>Objet du résultat d'une requête favourite</summary>
    /// <see cref="upload"></see>
    [DataContract]
    public class favourite : photo
    {
        
    }

    public delegate void FavouritePhotosEventHandler(object sender, FavouritePhotosEventArgs e);
    public class FavouritePhotosEventArgs : EventArgs
    {
        public FavouritePhotosEventArgs(ObservableCollection<favourite> fp)
        {
            _result = fp;
        }

        private ObservableCollection<favourite> _result;
        public ObservableCollection<favourite> result { get { return _result; } }
    }

    public partial class apitxt : api
    {

        public event FavouritePhotosEventHandler FavouritePhotosCompleted;

        #region favourite
        /// <summary>Liste les photos favorite de l'utilsiateur.</summary>
        /// <c>http://apitxt.hellotipi.com/photo/favourite</c>        
        /// <returns>La liste des photos favorite de l'utilisateur</returns>
        public void FavouritePhoto()
        {

            base.APICallCompleted += new APICallCompletedEventHandler(FavouritePhotosCallCompleted);

            GetUrlApi("photo/favourite.json");
        }

        void FavouritePhotosCallCompleted(object sender, ApiOpenReadCompletedEventArgs e)
        {
            try
            {
                FavouritePhotosCompleted.Invoke(sender, new FavouritePhotosEventArgs(serializeTools.Deserialize<ObservableCollection<favourite>>(e.Result)));
            }
            finally
            {
                base.APICallCompleted -= new APICallCompletedEventHandler(FavouritePhotosCallCompleted);
            }
        }

        #endregion

    }
}
